package protocol.JT808_2019;

import java.util.HashMap;

public class Handle808_2019JT82 implements IHandle808_2019JT {
    @Override
    public String handle(JT808_2019Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle8201(cmd);
            case 0x02:
                return handle8202(cmd);
            case 0x03:
                return handle8203(cmd);
            case 0x04:
                return handle8204(cmd);
            default:
                return "808-2019:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8204(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:链路检测");
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle8203(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:人工确认报警信息");
        builder.append("\r\n");
        builder.append("报警消息流水号:"+cmd.readWORD());
        builder.append("\r\n");

        int value = cmd.readDWORD();
        builder.append("人工确认报警类型:"+value);
        builder.append("\r\n");
        builder.append("    确认紧急报警(1)：" + (value & 0x01));
        builder.append("\r\n");
        builder.append("    确认危险报警(1)：" + (value >> 3 & 0x01));
        builder.append("\r\n");
        builder.append("    确认进出区域报警(1)：" + (value >> 20 & 0x01));
        builder.append("\r\n");
        builder.append("    确认进出路线报警(1)：" + (value >> 21 & 0x01));
        builder.append("\r\n");
        builder.append("    确认路段行驶时间不足/过长报警(1)：" + (value >> 22 & 0x01));
        builder.append("\r\n");
        builder.append("    确认车辆非法点火报警(1)：" + (value >> 27 & 0x01));
        builder.append("\r\n");
        builder.append("    确认车辆非法位移报警(1)：" + (value >> 28 & 0x01));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8202(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:临时位置跟踪控制");
        builder.append("\r\n");
        builder.append("时间间隔（秒）:"+cmd.readWORD());
        builder.append("\r\n");
        builder.append("位置跟踪有效期（秒）:"+cmd.readDWORD());
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle8201(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:查询终端位置信息");
        builder.append("\r\n");
        return builder.toString();
    }

}
